package com.gitee.yannzh.rune.core.exception;

/**
  * @description:
  * @author yann
  * @date 2022/2/15 14:19
  * @version：1.0
  */
public class ServiceException extends RuntimeException {

    private Throwable source;

    public ServiceException(Throwable exp)
    {
        super(exp);
        this.source = exp;
    }

    public ServiceException(String message)
    {
        super(message);
    }

    public ServiceException(String message, Throwable cause)
    {
        super(message, cause);
        this.source = cause;
    }

    public Throwable getSource(){
        if(this.source == null)
        {    return null;}
        if(this.source instanceof ServiceException)
        {   return  ((ServiceException)this.source).getSource();}
        return source;
    }

    public static ServiceException newInstance(String message){
        return new ServiceException(message);
    }
}
